package jsu.yym.tiktok.config;

import jsu.yym.tiktok.config.PasswordNotMatchedException;
import jsu.yym.tiktok.config.UserIsNullMatchedException;
import jsu.yym.tiktok.pojo.ResponseResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(PasswordNotMatchedException.class)
    @ResponseBody
    public ResponseResult handlePasswordNotMatched(PasswordNotMatchedException ex) {
        // 返回自定义状态码，如 401 Unauthorized
        return new ResponseResult<>(401,"密码错误");
    }

    @ExceptionHandler(UserIsNullMatchedException.class)
    @ResponseBody
    public ResponseResult UserIsNullMatchedExceptionMatched(UserIsNullMatchedException e)
    {
        return new ResponseResult(402,"用户不存在");
    }
}